package com.hmyd.hmyd_android.adapter;

import java.util.List;

import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.dto.ExchangeRecord;
import com.hmyd.hmyd_android.utils.Utils;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class ExchangeRecordAdapter extends BaseAdapter {
	private List<ExchangeRecord> mdatas;
	private LayoutInflater mInflater;

	public ExchangeRecordAdapter(Context context, List<ExchangeRecord> datas) {
		this.mdatas = datas;
		mInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return mdatas.size();
	}

	@Override
	public Object getItem(int position) {
		return mdatas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.view_shop_exchange_record, null);
			holder = new ViewHolder();
			holder.line = convertView.findViewById(R.id.line);
			holder.mTvName = (TextView) convertView.findViewById(R.id.tv_name);
			holder.mTvNumber = (TextView) convertView.findViewById(R.id.number);
			holder.mTvScore = (TextView) convertView.findViewById(R.id.score);
			holder.mTvTime = (TextView) convertView.findViewById(R.id.tv_time);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		ExchangeRecord item = mdatas.get(position);
		holder.mTvName.setText(item.nickname);
		holder.mTvNumber.setText(item.amount + "个");
		holder.mTvScore.setText(item.presentPrice + "");
		if (!TextUtils.isEmpty(item.createdTime)) {
			holder.mTvTime.setText(Utils.getDateString(Long.parseLong(item.createdTime)*1000));
		}
		

		if (position == mdatas.size() - 1) {
			holder.line.setVisibility(View.INVISIBLE);
		} else {
			holder.line.setVisibility(View.VISIBLE);
		}

		return convertView;
	}

	class ViewHolder {
		public TextView mTvName;
		public TextView mTvTime;
		public TextView mTvNumber;
		public TextView mTvScore;
		public View line;
	}

}
